package com.zlm.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工作经验枚举类
 * @Author: duyufu
 * @Date: 2019/4/24 13:08
 */
public enum ExperienceEnum {
	WORK_UNDEFINED(0, "不限"),
	WORK_ONE_YEAR(1, "1年以下"),
	WORK_TWO_YEAR(2, "1-3年"),
	WORK_THREE_YEAR(3, "3-5年"),
	WORK_FOUR_YEAR(4,"5-10年"),
	WORK_FIVE_YEAR(5, "10年以上");

	private Integer code;
	private String name;

	private ExperienceEnum(Integer code, String name) {
		this.code = code;
		this.name = name;
	}

	/**
	 * 把枚举转成json
	 * 
	 * @return
	 */
	public static String getWorkYearEnumJsonString() {
		StringBuilder builder = new StringBuilder("{");
		for (ExperienceEnum experienceEnum : ExperienceEnum.values()) {
			builder.append("\"" + experienceEnum.getCode() + "\":\"" + experienceEnum.getName() + "\",");
		}
		String json = builder.substring(0, builder.length() - 1) + "}";
		return json;
	}

	public static List getWorkYear() {
		List list = new ArrayList();
		Map<String, Object> map;
		for (ExperienceEnum experienceEnum : ExperienceEnum.values()) {
			map = new HashMap<String, Object>();
			map.put("code", experienceEnum.getCode());
			map.put("name", experienceEnum.getName());
			list.add(map);
		}
		return list;
	}

	public static List getWorkYearCodeList() {
	    List list = new ArrayList();
        for (ExperienceEnum experienceEnum : ExperienceEnum.values()) {
            list.add(experienceEnum.getCode());
        }
        return list;
    }

	public static String getNameByCode(Integer code) {
		for (ExperienceEnum experienceEnum : ExperienceEnum.values()) {
			if (code.equals(experienceEnum.getCode())) {
				return experienceEnum.getName();
			}
		}
		return null;

	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
